package com.zsummer.demo.rabbitmq.common.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author zsummer
 * @since 2021/12/9
 */
public class RabbitmqUtils {

    public static ConnectionFactory factory;

    static {
        factory = new ConnectionFactory();
        factory.setHost("dev128");
        factory.setPort(5672);
        factory.setVirtualHost("/test1");
        factory.setUsername("test1");
        factory.setPassword("test1");
    }

    // 创建连接
    public static Connection getConnection() throws Exception {
        return factory.newConnection();
    }

    // 关闭通道和连接
    public static void close(Connection connection, Channel channel) throws Exception {
        channel.close();
        connection.close();
    }

}
